package com.msb.serviceverificationcode.controller;

import com.msb.commons.response.NumberCodeResponse;
import com.msb.commons.response.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: chshh
 * @version: 1.0
 */
@RestController
public class NumberCodeController {

    /**
     * 生成验证码
     * @param size
     * @return
     */
    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable int size){

        //生成验证码
        double random = (Math.random()*9+1) * (Math.pow(10,size-1)); //10的多少次方
        int randomInt = (int) random;

        //定义返回值
        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode(randomInt);

        return ResponseResult.success(response);
    }
}
